package KLTN;

import java.awt.Panel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;

import de.bwaldvogel.liblinear.InvalidInputDataException;
import excel.ExcelToText;

import thesis.ThesisDDAGHackCode;
import thesis.ThesisHAH;

import libsvm.svm;

public class KLTN_UI {

	private JFrame MyFrame;
	private JProgressBar progressBar;
	private JProgressBar progressBar_DDAGSVM;
	private JProgressBar progressBar_HAH;
	private JProgressBar progressBar_Excel;
	private JProgressBar progressBar_Standardize;
	private JFileChooser mFileChooser;

	private JTabbedPane tab;
	private Panel tab_SVC;
	private Panel tab_DDAGSVM;
	private Panel tab_HAH;
	private Panel tab_EXCEL;
	private Panel tab_Standardize;

	private JTextField txt_train;
	private JTextField txt_train_DDAGSVM;
	private JTextField txt_train_HAH;
	private JTextField txt_input_Excel;
	private JTextField txt_output_Excel;
	private JTextField txt_input_Standard;
	private JTextField txt_output_Standard;

	private JButton btn_train;
	private JButton btn_model;
	private JButton btn_predict;

	private JButton btn_train_DDAGSVM;
	private JButton btn_model_DDAGSVM;
	private JButton btn_predict_DDAGSVM;

	private JButton btn_train_HAH;
	private JButton btn_model_HAH;
	private JButton btn_predict_HAH;

	private JButton btn_input_Excel;
	private JButton btn_output_Excel;
	private JButton btn_convert_Excel;
	
	private JButton btn_input_Standard;
	private JButton btn_output_Standard;
	private JButton btn_Standardize;

	private JTextArea txt_result;
	private JTextArea txt_result_DDAGSVM;
	private JTextArea txt_result_HAH;
	private JTextArea txt_result_Excel;
	private JTextArea txt_result_Standardlize;

	private String path_test, path_model, path_out, path_train, path_input,
			path_output;

	private int _time;

	private Task task;

	public KLTN_UI() {

		initUI();
		build_UI(MyFrame);

	}

	// ham khoi tao
	private JFrame initUI() {

		MyFrame = new JFrame();
		mFileChooser = new JFileChooser();

		progressBar = new JProgressBar(0, 100);
		progressBar.setValue(0);
		progressBar.setStringPainted(true);
		
		progressBar_Excel = new JProgressBar(0, 100);
		progressBar_Excel.setValue(0);
		progressBar_Excel.setStringPainted(true);

		txt_result = new JTextArea();
		JScrollPane result_scroll = new JScrollPane(txt_result,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		tab = new JTabbedPane();
		tab_SVC = new Panel();
		tab_DDAGSVM = new Panel();
		tab_HAH = new Panel();
		tab_EXCEL = new Panel();
		tab_Standardize  = new Panel();

		txt_train = new JTextField();

		// su kien nut Train
		btn_train = new JButton("Train");
		btn_train.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				task = new Task();
				int returnval = mFileChooser.showOpenDialog(MyFrame);

				if (returnval == JFileChooser.APPROVE_OPTION) {
					File selectFile = mFileChooser.getSelectedFile();
					path_train = selectFile.getPath();
					try {

						svm_train train = new svm_train(path_train, 1);
						path_model = path_train + ".model";
						train.run(path_model);
						task.addPropertyChangeListener(new PropertyChangeListener() {

							@Override
							public void propertyChange(PropertyChangeEvent evt) {
								// TODO Auto-generated method stub
								if ("progress" == evt.getPropertyName()) {
									int progress = (Integer) evt.getNewValue();
									progressBar.setValue(progress);
								}
							}
						});
						task.execute();

					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}

		});

		// su kien nut model
		btn_model = new JButton("Model");
		btn_model.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				int returnval = mFileChooser.showOpenDialog(MyFrame);
				if (returnval == JFileChooser.APPROVE_OPTION) {
					File selectFile = mFileChooser.getSelectedFile();
					path_model = selectFile.getPath();
				}
			}
		});

		// su kien nut predict
		btn_predict = new JButton("Predict");
		btn_predict.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				int returnval = mFileChooser.showOpenDialog(MyFrame);
				if (returnval == JFileChooser.APPROVE_OPTION) {
					File selectFile = mFileChooser.getSelectedFile();
					path_test = selectFile.getPath();
					path_out = path_test.replace(selectFile.getName(),
							"result.data");
					svm_predict predict = new svm_predict();
					try {
						predict.run(path_test, path_model, path_out);
						double rate = predict.rate;
						String str_rate = "Ti le chinh xac:" + rate + "\n";
						LoadTextFile loadfile = new LoadTextFile();
						String content = str_rate
								+ loadfile.readTextFile(path_out);
						txt_result.setText(content);

					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			}
		});
		// layout for tab_SVC
		SpringLayout layout_tab_SVC = new SpringLayout();

		layout_tab_SVC.putConstraint(SpringLayout.NORTH, btn_train, 5,
				SpringLayout.NORTH, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.WEST, btn_train, 5,
				SpringLayout.WEST, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.EAST, btn_train, -5,
				SpringLayout.WEST, progressBar);

		layout_tab_SVC.putConstraint(SpringLayout.NORTH, progressBar, 8,
				SpringLayout.NORTH, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.EAST, progressBar, -5,
				SpringLayout.EAST, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.WEST, progressBar, 90,
				SpringLayout.WEST, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.NORTH, btn_model, 38,
				SpringLayout.NORTH, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.WEST, btn_model, 5,
				SpringLayout.WEST, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.NORTH, btn_predict, 70,
				SpringLayout.NORTH, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.WEST, btn_predict, 5,
				SpringLayout.WEST, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.NORTH, result_scroll, 38,
				SpringLayout.NORTH, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.WEST, result_scroll, 90,
				SpringLayout.WEST, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.EAST, result_scroll, -5,
				SpringLayout.EAST, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.SOUTH, result_scroll, -5,
				SpringLayout.SOUTH, tab_SVC);

		layout_tab_SVC.putConstraint(SpringLayout.EAST, btn_predict, -5,
				SpringLayout.WEST, result_scroll);

		layout_tab_SVC.putConstraint(SpringLayout.EAST, btn_model, -5,
				SpringLayout.WEST, result_scroll);

		tab_SVC.setLayout(layout_tab_SVC);

		// them cac dieu khien vao
		tab_SVC.add(btn_train);
		tab_SVC.add(progressBar);
		tab_SVC.add(btn_model);
		tab_SVC.add(btn_predict);
		tab_SVC.add(result_scroll);

		// Giao Dien DDAGSVM
		progressBar_DDAGSVM = new JProgressBar(0, 100);
		progressBar_DDAGSVM.setValue(0);
		progressBar_DDAGSVM.setStringPainted(true);
		txt_result_DDAGSVM = new JTextArea();
		txt_train_DDAGSVM = new JTextField();

		JScrollPane result_scroll_DDAGSVM = new JScrollPane(txt_result_DDAGSVM,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		// xu kien cua nut train DDAG
		btn_train_DDAGSVM = new JButton("Input");
		btn_train_DDAGSVM.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				int returnval = mFileChooser.showOpenDialog(MyFrame);

				if (returnval == JFileChooser.APPROVE_OPTION) {
					File selectFile = mFileChooser.getSelectedFile();
					path_train = selectFile.getPath();
					txt_train_DDAGSVM.setText(path_train);

				}
			}
		});

		// xu kien cua nut predict DDAG
		btn_predict_DDAGSVM = new JButton("Predict");
		btn_predict_DDAGSVM.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				task = new Task();
				ThesisDDAGHackCode thesisDDAGHackCode = new ThesisDDAGHackCode();

				try {
					thesisDDAGHackCode.main(path_train);
				} catch (IOException | InvalidInputDataException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

				task.addPropertyChangeListener(new PropertyChangeListener() {

					@Override
					public void propertyChange(PropertyChangeEvent evt) {
						// TODO Auto-generated method stub
						if ("progress" == evt.getPropertyName()) {
							// int progress = (Integer) evt.getNewValue();
							progressBar_DDAGSVM.setValue(100);
						}
					}
				});
				task.execute();

				txt_result_DDAGSVM.setText(thesisDDAGHackCode.result);
			}
		});

		// layout for tab_DDAG
		SpringLayout layout_tab_DDAGSVM = new SpringLayout();

		layout_tab_DDAGSVM.putConstraint(SpringLayout.NORTH, btn_train_DDAGSVM,
				5, SpringLayout.NORTH, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.WEST, btn_train_DDAGSVM,
				5, SpringLayout.WEST, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.NORTH, txt_train_DDAGSVM,
				8, SpringLayout.NORTH, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.WEST, txt_train_DDAGSVM,
				90, SpringLayout.WEST, tab_DDAGSVM);
		layout_tab_DDAGSVM.putConstraint(SpringLayout.EAST, txt_train_DDAGSVM,
				-5, SpringLayout.EAST, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.EAST, btn_train_DDAGSVM,
				-5, SpringLayout.WEST, txt_train_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.NORTH,
				progressBar_DDAGSVM, 40, SpringLayout.NORTH, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.EAST,
				progressBar_DDAGSVM, -5, SpringLayout.EAST, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.WEST,
				progressBar_DDAGSVM, 90, SpringLayout.WEST, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.NORTH,
				btn_predict_DDAGSVM, 38, SpringLayout.NORTH, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.WEST,
				btn_predict_DDAGSVM, 5, SpringLayout.WEST, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.NORTH,
				result_scroll_DDAGSVM, 70, SpringLayout.NORTH, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.WEST,
				result_scroll_DDAGSVM, 5, SpringLayout.WEST, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.EAST,
				result_scroll_DDAGSVM, -5, SpringLayout.EAST, tab_DDAGSVM);

		layout_tab_DDAGSVM.putConstraint(SpringLayout.SOUTH,
				result_scroll_DDAGSVM, -5, SpringLayout.SOUTH, tab_DDAGSVM);

		layout_tab_DDAGSVM
				.putConstraint(SpringLayout.EAST, btn_predict_DDAGSVM, -5,
						SpringLayout.WEST, progressBar_DDAGSVM);

		tab_DDAGSVM.setLayout(layout_tab_DDAGSVM);

		// them cac dieu khien vao tab_DDAGSVM
		tab_DDAGSVM.add(btn_train_DDAGSVM);
		tab_DDAGSVM.add(btn_predict_DDAGSVM);
		tab_DDAGSVM.add(result_scroll_DDAGSVM);
		tab_DDAGSVM.add(progressBar_DDAGSVM);
		tab_DDAGSVM.add(txt_train_DDAGSVM);

		// Giao Dien HAH
		progressBar_HAH = new JProgressBar(0, 100);
		progressBar_HAH.setValue(0);
		progressBar_HAH.setStringPainted(true);
		txt_result_HAH = new JTextArea();
		txt_train_HAH = new JTextField();

		JScrollPane result_scroll_HAH = new JScrollPane(txt_result_HAH,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		// xu kien cua nut train HAH
		btn_train_HAH = new JButton("Input");
		btn_train_HAH.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				int returnval = mFileChooser.showOpenDialog(MyFrame);

				if (returnval == JFileChooser.APPROVE_OPTION) {
					File selectFile = mFileChooser.getSelectedFile();
					path_train = selectFile.getPath();
					txt_train_HAH.setText(path_train);

				}
			}
		});

		// xu kien cua nut predict HAH
		btn_predict_HAH = new JButton("Predict");
		btn_predict_HAH.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				task = new Task();

				ThesisHAH thesisHAH = new ThesisHAH();
				try {
					thesisHAH.main(path_train);
					task.addPropertyChangeListener(new PropertyChangeListener() {

						@Override
						public void propertyChange(PropertyChangeEvent evt) {
							// TODO Auto-generated method stub
							if ("progress" == evt.getPropertyName()) {
								// int progress = (Integer) evt.getNewValue();
								progressBar_HAH.setValue(100);
							}
						}
					});
					task.execute();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				txt_result_HAH.setText(thesisHAH.result);
			}
		});

		// layout for tab_HAH
		SpringLayout layout_tab_HAH = new SpringLayout();

		layout_tab_HAH.putConstraint(SpringLayout.NORTH, btn_train_HAH, 5,
				SpringLayout.NORTH, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.WEST, btn_train_HAH, 5,
				SpringLayout.WEST, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.NORTH, txt_train_HAH, 8,
				SpringLayout.NORTH, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.WEST, txt_train_HAH, 90,
				SpringLayout.WEST, tab_HAH);
		layout_tab_HAH.putConstraint(SpringLayout.EAST, txt_train_HAH, -5,
				SpringLayout.EAST, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.EAST, btn_train_HAH, -5,
				SpringLayout.WEST, txt_train_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.NORTH, progressBar_HAH, 40,
				SpringLayout.NORTH, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.EAST, progressBar_HAH, -5,
				SpringLayout.EAST, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.WEST, progressBar_HAH, 90,
				SpringLayout.WEST, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.NORTH, btn_predict_HAH, 38,
				SpringLayout.NORTH, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.WEST, btn_predict_HAH, 5,
				SpringLayout.WEST, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.NORTH, result_scroll_HAH, 70,
				SpringLayout.NORTH, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.WEST, result_scroll_HAH, 5,
				SpringLayout.WEST, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.EAST, result_scroll_HAH, -5,
				SpringLayout.EAST, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.SOUTH, result_scroll_HAH, -5,
				SpringLayout.SOUTH, tab_HAH);

		layout_tab_HAH.putConstraint(SpringLayout.EAST, btn_predict_HAH, -5,
				SpringLayout.WEST, progressBar_HAH);

		tab_HAH.setLayout(layout_tab_HAH);

		// them cac dieu khien vao tab_HAH
		tab_HAH.add(btn_train_HAH);
		tab_HAH.add(btn_predict_HAH);
		tab_HAH.add(result_scroll_HAH);
		tab_HAH.add(progressBar_HAH);
		tab_HAH.add(txt_train_HAH);

		// Giao Dien Excel
		progressBar_Excel = new JProgressBar(0, 100);
		progressBar_Excel.setValue(0);
		progressBar_HAH.setStringPainted(true);
		txt_result_Excel = new JTextArea();
		txt_input_Excel = new JTextField();
		txt_output_Excel = new JTextField();

		// Tham số để xuất excel
		final String[] args = new String[2];

		JScrollPane result_scroll_Excel = new JScrollPane(txt_result_Excel,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		// xu kien cua nut input Excel
		btn_input_Excel = new JButton("Input");
		btn_input_Excel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				int returnval = mFileChooser.showOpenDialog(MyFrame);

				if (returnval == JFileChooser.APPROVE_OPTION) {
					File selectFile = mFileChooser.getSelectedFile();
					path_input = selectFile.getPath();
					txt_input_Excel.setText(path_input);
					args[0] = path_input;
				}
			}
		});

		// xu kien cua nut output Excel
		btn_output_Excel = new JButton("  Output ");
		btn_output_Excel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				// int returnval = mFileChooser.showOpenDialog(MyFrame);

				// if (returnval == JFileChooser.APPROVE_OPTION) {
				mFileChooser
						.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				mFileChooser.showSaveDialog(null);
				path_output = mFileChooser.getSelectedFile().toString();
				txt_output_Excel.setText(path_output);
				args[1] = path_output;
				// }
			}
		});

		// xu kien cua nut convert Excel
		btn_convert_Excel = new JButton(" Convert");
		btn_convert_Excel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				 task = new Task();

				ExcelToText excelToText = new ExcelToText();
				try {
					excelToText.main(args);
				} catch (FileNotFoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

				task.addPropertyChangeListener(new PropertyChangeListener() {

					@Override
					public void propertyChange(PropertyChangeEvent evt) {
						// TODO Auto-generated method stub
//						if ("progress" == evt.getPropertyName()) {
							// int progress = (Integer) evt.getNewValue();
							progressBar_Excel.setValue(100);
//						}
					}
				});
				task.execute();

			}
		});

		// layout for tab_Excel
		SpringLayout layout_tab_Excel = new SpringLayout();

		layout_tab_Excel.putConstraint(SpringLayout.NORTH, btn_input_Excel, 5,
				SpringLayout.NORTH, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.WEST, btn_input_Excel, 5,
				SpringLayout.WEST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.NORTH, txt_input_Excel, 8,
				SpringLayout.NORTH, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.WEST, txt_input_Excel, 90,
				SpringLayout.WEST, tab_EXCEL);
		layout_tab_Excel.putConstraint(SpringLayout.EAST, txt_input_Excel, -5,
				SpringLayout.EAST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.EAST, btn_input_Excel, -5,
				SpringLayout.WEST, txt_input_Excel);

		layout_tab_Excel.putConstraint(SpringLayout.NORTH, txt_output_Excel,
				40, SpringLayout.NORTH, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.EAST, txt_output_Excel, -5,
				SpringLayout.EAST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.WEST, txt_output_Excel, 90,
				SpringLayout.WEST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.NORTH, btn_output_Excel,
				38, SpringLayout.NORTH, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.WEST, btn_output_Excel, 5,
				SpringLayout.WEST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.NORTH, btn_convert_Excel,
				35, SpringLayout.NORTH, btn_output_Excel);

		layout_tab_Excel.putConstraint(SpringLayout.WEST, btn_convert_Excel, 5,
				SpringLayout.WEST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.SOUTH, progressBar_Excel,
				-205, SpringLayout.SOUTH, result_scroll_Excel);

		layout_tab_Excel.putConstraint(SpringLayout.EAST, progressBar_Excel,
				-5, SpringLayout.EAST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.WEST, progressBar_Excel,
				90, SpringLayout.WEST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.NORTH, progressBar_Excel,
				75, SpringLayout.NORTH, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.NORTH, result_scroll_Excel,
				110, SpringLayout.NORTH, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.WEST, result_scroll_Excel,
				5, SpringLayout.WEST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.EAST, result_scroll_Excel,
				-5, SpringLayout.EAST, tab_EXCEL);

		layout_tab_Excel.putConstraint(SpringLayout.SOUTH, result_scroll_Excel,
				-5, SpringLayout.SOUTH, tab_EXCEL);
		//
		// layout_tab_Excel.putConstraint(SpringLayout.EAST, btn_output_Excel,
		// -5,
		// SpringLayout.WEST, tab_EXCEL);

		tab_EXCEL.setLayout(layout_tab_Excel);

		// them cac dieu khien vao tab_Excel
		tab_EXCEL.add(btn_input_Excel);
		tab_EXCEL.add(txt_input_Excel);
		tab_EXCEL.add(txt_output_Excel);
		tab_EXCEL.add(btn_output_Excel);
		tab_EXCEL.add(btn_convert_Excel);
		tab_EXCEL.add(progressBar_Excel);
		tab_EXCEL.add(result_scroll_Excel);
		

		// Giao Dien Chuna hoa tieng Viet
				progressBar_Standardize = new JProgressBar(0, 100);
				progressBar_Standardize.setValue(0);
				progressBar_Standardize.setStringPainted(true);
				txt_result_Standardlize = new JTextArea();
				txt_input_Standard = new JTextField();
				txt_output_Standard = new JTextField();

				JScrollPane result_scroll_Standardize = new JScrollPane(txt_result_Standardlize,
						JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
						JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

				// xu kien cua nut input Standardlize
				btn_input_Standard = new JButton("Input");
				btn_input_Standard.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent arg0) {
						// TODO Auto-generated method stub
						int returnval = mFileChooser.showOpenDialog(MyFrame);

						if (returnval == JFileChooser.APPROVE_OPTION) {
							File selectFile = mFileChooser.getSelectedFile();
							path_input = selectFile.getPath();
							txt_input_Standard.setText(path_input);
//							args[0] = path_input;
						}
					}
				});

				// xu kien cua nut predict Standardlize
//				btn_predict_DDAGSVM = new JButton("Predict");
//				btn_predict_DDAGSVM.addActionListener(new ActionListener() {
//					@Override
//					public void actionPerformed(ActionEvent e) {
//						// TODO Auto-generated method stub
//						task = new Task();
//						ThesisDDAGHackCode thesisDDAGHackCode = new ThesisDDAGHackCode();
//
//						try {
//							thesisDDAGHackCode.main(path_train);
//						} catch (IOException | InvalidInputDataException e1) {
//							// TODO Auto-generated catch block
//							e1.printStackTrace();
//						}
//
//						task.addPropertyChangeListener(new PropertyChangeListener() {
//
//							@Override
//							public void propertyChange(PropertyChangeEvent evt) {
//								// TODO Auto-generated method stub
//								if ("progress" == evt.getPropertyName()) {
//									// int progress = (Integer) evt.getNewValue();
//									progressBar_DDAGSVM.setValue(100);
//								}
//							}
//						});
//						task.execute();
//
//						txt_result_DDAGSVM.setText(thesisDDAGHackCode.result);
//					}
//				});

				// layout for Standardlize
				SpringLayout layout_tab_Standardlize = new SpringLayout();

				layout_tab_Standardlize.putConstraint(SpringLayout.NORTH, btn_input_Standard,
						5, SpringLayout.NORTH, tab_Standardize);

				layout_tab_Standardlize.putConstraint(SpringLayout.WEST, btn_input_Standard,
						5, SpringLayout.WEST, tab_Standardize);

				layout_tab_Standardlize.putConstraint(SpringLayout.NORTH, btn_input_Standard,
						8, SpringLayout.NORTH, tab_Standardize);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.WEST, txt_train_DDAGSVM,
//						90, SpringLayout.WEST, tab_DDAGSVM);
//				layout_tab_Standardlize.putConstraint(SpringLayout.EAST, txt_train_DDAGSVM,
//						-5, SpringLayout.EAST, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.EAST, btn_train_DDAGSVM,
//						-5, SpringLayout.WEST, txt_train_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.NORTH,
//						progressBar_DDAGSVM, 40, SpringLayout.NORTH, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.EAST,
//						progressBar_DDAGSVM, -5, SpringLayout.EAST, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.WEST,
//						progressBar_DDAGSVM, 90, SpringLayout.WEST, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.NORTH,
//						btn_predict_DDAGSVM, 38, SpringLayout.NORTH, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.WEST,
//						btn_predict_DDAGSVM, 5, SpringLayout.WEST, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.NORTH,
//						result_scroll_DDAGSVM, 70, SpringLayout.NORTH, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.WEST,
//						result_scroll_DDAGSVM, 5, SpringLayout.WEST, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.EAST,
//						result_scroll_DDAGSVM, -5, SpringLayout.EAST, tab_DDAGSVM);
//
//				layout_tab_Standardlize.putConstraint(SpringLayout.SOUTH,
//						result_scroll_DDAGSVM, -5, SpringLayout.SOUTH, tab_DDAGSVM);
//
//				layout_tab_Standardlize
//						.putConstraint(SpringLayout.EAST, btn_predict_DDAGSVM, -5,
//								SpringLayout.WEST, progressBar_DDAGSVM);

				tab_Standardize.setLayout(layout_tab_Standardlize);

				// them cac dieu khien vao tab_DDAGSVM
				tab_Standardize.add(btn_input_Standard);
//				tab_Standardize.add(btn_predict_DDAGSVM);
//				tab_Standardize.add(result_scroll_DDAGSVM);
//				tab_Standardize.add(progressBar_DDAGSVM);
//				tab_Standardize.add(txt_train_DDAGSVM);
				
		
		// add childtab to tab
		tab.add(tab_Standardize, "Article Standardization");
		tab.add(tab_EXCEL, "Convert Excel");
		tab.add(tab_SVC, "SVC");
		tab.add(tab_DDAGSVM, "DDAG");
		tab.add(tab_HAH, "HAH");
		

		MyFrame.add(tab);
		return MyFrame;
	}

	// ham build frame
	private static void build_UI(JFrame frame) {

		frame.setTitle("Phân đa lớp văn bản với DDAG & HAH");
		frame.setSize(700, 375);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				new KLTN_UI();
			}
		});
	}

}

class Task extends SwingWorker<Void, Void> {

	@Override
	public Void doInBackground() {

		Random random = new Random();
		int progress = 0;
		// Initialize progress property.
		setProgress(0);
		while (progress < 100) {
			// Sleep for up to one second.
			try {
				Thread.sleep(random.nextInt(1000));
			} catch (InterruptedException ignore) {
			}
			// Make random progress.
			progress += random.nextInt(10);
			setProgress(Math.min(progress, 100));

		}
		return null;
	}

	@Override
	public void done() {

	}
}
